package com.wave12.pro_cart.controller;

import com.wave12.pro_cart.entity.Cart;
import com.wave12.pro_cart.entity.ProCart;
import com.wave12.pro_cart.entity.User;
import com.wave12.pro_cart.service.UserSeriver;
import com.wave12.utility.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Controller
@RequestMapping(value = "/user")
public class UserController {
    
    @Autowired
    private UserSeriver userSeriver;

    @CrossOrigin
    @ResponseBody
    @RequestMapping(value="/info", method = RequestMethod.GET)
    public Result getOneProCartDetail(HttpServletRequest request){
        Map<String, Object> data = new HashMap<>();
        data.put("name", "张三");
        data.put("avatar", "zhangsan");

        Set<String> roles = new HashSet<String>();
        roles.add("1");
        Set<String> permissions =new HashSet<String>();
        permissions.add("GET /aaa");
        permissions.add("POST /bbb");
        data.put("roles", roles);
        data.put("perms", permissions);
        return Result.succeed(0, "", data);
    }
    
    @ResponseBody
    @RequestMapping(value="/getUserById", method = RequestMethod.POST)
    public Result getUserDetail(HttpServletRequest request,String userId){
        User user = userSeriver.getUserById(userId);
    
        return Result.succeed(0, "查询成功", user);
    }
    

}
